package com.ruoyi.postulant.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.postulant.domain.ActFile;
import com.ruoyi.postulant.service.IActFileService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 活动文件Controller
 * 
 * @author wanghong
 * @date 2025-03-15
 */
@RestController
@RequestMapping("/postulant/file")
public class ActFileController extends BaseController
{
    @Autowired
    private IActFileService actFileService;

    /**
     * 查询活动文件列表
     */
    @PreAuthorize("@ss.hasPermi('postulant:file:list')")
    @GetMapping("/list")
    public TableDataInfo list(ActFile actFile)
    {
        startPage();
        List<ActFile> list = actFileService.selectActFileList(actFile);
        return getDataTable(list);
    }

    /**
     * 导出活动文件列表
     */
    @PreAuthorize("@ss.hasPermi('postulant:file:export')")
    @Log(title = "活动文件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ActFile actFile)
    {
        List<ActFile> list = actFileService.selectActFileList(actFile);
        ExcelUtil<ActFile> util = new ExcelUtil<ActFile>(ActFile.class);
        util.exportExcel(response, list, "活动文件数据");
    }

    /**
     * 获取活动文件详细信息
     */
    @PreAuthorize("@ss.hasPermi('postulant:file:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(actFileService.selectActFileById(id));
    }

    /**
     * 新增活动文件
     */
    @PreAuthorize("@ss.hasPermi('postulant:file:add')")
    @Log(title = "活动文件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ActFile actFile)
    {
        return toAjax(actFileService.insertActFile(actFile));
    }

    /**
     * 修改活动文件
     */
    @PreAuthorize("@ss.hasPermi('postulant:file:edit')")
    @Log(title = "活动文件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ActFile actFile)
    {
        return toAjax(actFileService.updateActFile(actFile));
    }

    /**
     * 删除活动文件
     */
    @PreAuthorize("@ss.hasPermi('postulant:file:remove')")
    @Log(title = "活动文件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(actFileService.deleteActFileByIds(ids));
    }
}
